<!--- get records for the eform to add or edit --->
<CFQUERY NAME="GetEntry" DATASOURCE="#table_dsn#" MAXROWS=1>
   	SELECT *
	FROM #GetForm.TABLENAME_FK#
	WHERE
		(PERSONNELIDNO = '#GetEmployee.PERSONNELIDNO#')
		<CFLOOP INDEX="x" FROM="1" TO="5">
			<CFIF evaluate("GetForm.PK_FIELD" & x) NEQ "">
				<CFIF IsDefined("url.sendasemail")>
					<CFSET theVal = evaluate("url." & evaluate("GetForm.PK_FIELD" & x))>
					AND (#ucase(evaluate("GetForm.PK_FIELD" & x))# = '#theVal#')
				<CFELSE>
					<CFSET theVal = evaluate("form.edt" & evaluate("GetForm.PK_FIELD" & x))>
					AND (#ucase(evaluate("GetForm.PK_FIELD" & x))# = '#theVal#')
				</CFIF>
			</CFIF>
		</CFLOOP>
</CFQUERY>
<!--- Get Infocards by: Maan --->
<CFIF GetFormDtl.RECORDCOUNT>
	<CFQUERY NAME="GetDtlEntry" DATASOURCE="#table_dsn#" MAXROWS=1>
		SELECT *
		FROM #GetFormDtl.DETAILTABLE#
		WHERE
			#GetFormDtl.DTL_FIELD1# = '#evaluate("GetEntry." & GetFormDtl.LNK_FIELD1)#'
			<CFLOOP INDEX="nFld" FROM="2" TO="5">
				<CFIF evaluate("GetFormDtl.DTL_FIELD" & nFld) NEQ "" AND evaluate("GetFormDtl.LNK_FIELD" & nFld) NEQ "">
					AND #evaluate("GetFormDtl.DTL_FIELD" & nFld)# = '#evaluate("GetEntry." & (evaluate("GetFormDtl.LNK_FIELD" & nFld)))#'
				</CFIF>
			</CFLOOP>
	</CFQUERY>
</CFIF>
<CFIF NOT(GetEntry.RecordCount)>
	<CFSET sTitle="Editing " & GetForm.DESCRIPTION>
	<CFMODULE TEMPLATE="#client.common_path#cfm_wswindow.cfm" TITLE=sTitle>
	<BR><BR><B>Unauthorized access detected!</B><BR><BR>
	Please use the standard editor to avoid
	being reported for illegal use of the software.
	<CFMODULE TEMPLATE="#client.common_path#cfm_wswindow.cfm" TOP="False">
	<CFABORT>
</CFIF>

<CFSET sTitle = "#GetForm.DESCRIPTION#">
<CFSET sBody = "">
<CFOUTPUT QUERY="GetFields" GROUP="FIELDGROUP">
	<CFOUTPUT>
		<CFSET sEntryValue = #evaluate("GetEntry." & COLUMNNAME)#>

		<!--- Exclude fields with null value --->
		<CFIF Trim(sEntryValue) NEQ "">
			<CFIF FIELDGROUP IS NOT "">
				<CFSET sBody = sBody & "~DELIMIT~!GROUPING!#FIELDGROUP#">
			</CFIF>

			<CFSET sBody = sBody & "~DELIMIT~" & "#COLUMNDESC#">

			<CFSWITCH EXPRESSION="#lcase(COLUMNTYPE)#">
		    <CFCASE VALUE="ftinteger,ftsmallint,ftfloat">
				<CFSET sBody = sBody & "~DELIMIT~" & "#sEntryValue#">
			</CFCASE>
		    <CFCASE VALUE="ftdatetime">
				<CFSET sBody = sBody & "~DELIMIT~" & "#DateFormat(sEntryValue,'mmm dd, yyyy')#">
			</CFCASE>
		    <CFCASE VALUE="ftblob,ftgraphic">
				<CFSET sBody = sBody & "~DELIMIT~" & "interface not supported.">
			</CFCASE>
		    <CFCASE VALUE="ftmemo">
				<CFSET sBody = sBody & "~DELIMIT~" & "!FTMEMO!#sEntryValue#">
			</CFCASE>
			<CFDEFAULTCASE>
				<CFSET sBody = sBody & "~DELIMIT~" & "#sEntryValue#">

				<!--- there's a lookup --->
				<CFQUERY NAME="GetLookup" DATASOURCE="#client.global_dsn#">
						SELECT A.*, B.LEVELID
						FROM GSTLOOKUP A, GRGBOSETABLE B
						WHERE
							(A.MASTERTABLE = '#GetForm.TABLENAME_FK#') AND
							(A.MASTERFIELD = '#COLUMNNAME#') AND
							(A.LOOKUPTABLE = B.TABLENAME)
				</CFQUERY>

				<CFIF GetLookup.RecordCount>
					<CFSET sBody = sBody & " - ">
					<CFSET sLkValue = "">

					<CFIF (#trim(GetLookup.LEVELID)# IS "") OR
							(#trim(GetLookup.LOOKUPKEYFIELD)# IS "") OR
							(#trim(GetLookup.LOOKUPRESULTFIELD)# IS "") OR
							(#trim(GetLookup.LOOKUPTABLE)# IS "")>
						<CFSET sBody = sBody & "Lookup not properly setup.">
					<CFELSE>
						<!--- get the description in the lookup --->
						<CFIF sEntryValue IS NOT "">
							<CFMODULE TEMPLATE="#client.common_path#cfm_leveldsn.cfm" DBLEVEL="#GetLookup.LEVELID#">
							<CFSET lk_dsn = DSN>

							<CFQUERY NAME="GetLkDesc" DATASOURCE="#lk_dsn#">
								SELECT #GetLookup.LOOKUPRESULTFIELD#
								<!--- For extra lookup description --->
								<CFIF Trim(GetLookup.EXTRARESULTFLD) NEQ "">
									,#GetLookup.EXTRARESULTFLD#
								</CFIF>
								FROM #GetLookup.LOOKUPTABLE#
								WHERE
									(#GetLookup.LOOKUPKEYFIELD# = '#sEntryValue#')
							</CFQUERY>

							<CFIF GetLkDesc.RecordCount>
								<CFSET sBody = sBody & #evaluate("GetLkDesc." & GetLookup.LOOKUPRESULTFIELD)#>

								<CFIF Trim(GetLookup.EXTRARESULTFLD) NEQ "">
									<!--- Get the description and datatype of display fields for lookup --->
									<CFSET sComma="">
									<CFQUERY NAME="qryDispLkUp" DATASOURCE=#client.global_dsn#>
										SELECT COLUMNNAME, COLUMNDESC
										FROM GRGBOSETABLEFIELDS
										WHERE (TABLENAME = '#Trim(GetLookup.LOOKUPTABLE)#') AND
											  (
											  	COLUMNNAME IN (
										  	<CFLOOP LIST="#GetLookup.EXTRARESULTFLD#" INDEX="x">
												#sComma# '#Trim(x)#'
												<CFSET sComma=",">
											</CFLOOP>
											  )
											  )
									</CFQUERY>
									<CFSET lstKeyValue=Valuelist(qryDispLkUp.COLUMNNAME)>

									<CFLOOP LIST="#GetLookup.EXTRARESULTFLD#" INDEX="x">
										<CFSET x = trim(x)>
										<CFSET sLkValue = evaluate("GetLkDesc." & #x#)>
										<!--- Exclude fields with null values --->
										<CFIF Trim(sLkValue) NEQ "">
											<CFSET nPos=ListFindNocase(#lstKeyValue#, #x#)>
											<CFIF nPos NEQ 0>
												<CFSET sColDesc=#qryDispLkUp.COLUMNDESC[nPos]#>
											<CFELSE>
												<CFSET sColDesc="[No Description]">
											</CFIF>

											<CFSET sBody = sBody & "~DELIMIT~" & "#sColDesc# ">

											<CFIF IsDate(sLkValue) AND NOT IsNumericDate(sLkValue)>
												<CFSET sLkValue=DateFormat(sLkValue, "mm/dd/yyyy")>
											</CFIF>

											<CFSET sBody = sBody & "~DELIMIT~" & #sLkValue#>
										</CFIF>
									</CFLOOP>
								</CFIF>
							<CFELSE>
								<CFSET sBody = sBody & "[value not found in the lookup.]">
							</CFIF>
						</CFIF>
					</CFIF>
				</CFIF>
			</CFDEFAULTCASE>
			</CFSWITCH>
		</CFIF>
	</CFOUTPUT>
</CFOUTPUT>
<CFLOOP QUERY="GetFormDtl">
	<CFQUERY NAME="GetDtlFields" DATASOURCE=#client.global_dsn#>
		SELECT *
		FROM GRGBOSETABLEFIELDS
		WHERE
			(TABLENAME  = '#DETAILTABLE#') AND
			(ISVISIBLEEVIEW    = 'Y' OR ISVISIBLEEFORM IS NULL) AND
			(COLUMNNAME <> 'PERSONNELIDNO') AND
			(COLUMNNAME <> 'RECDATECREATED') AND
			(COLUMNNAME <> 'RECCREATEDBY') AND
			(COLUMNNAME <> 'USERID') AND
			(COLUMNNAME <> 'DATELASTUPDATE') AND
			(COLUMNNAME <> 'TIMELASTUPDATE') AND
			(COLUMNNAME <> 'ROUTEID') AND
			(#sqlSTRLEN#(COLUMNDESC) > 0)
		ORDER BY FIELDGROUP, COLUMNORDER, COLUMNDESC, COLUMNNAME
	</CFQUERY>
	<CFQUERY NAME="GetDtlEntry" DATASOURCE="#table_dsn#" MAXROWS=1>
		SELECT *
		FROM #GetFormDtl.DETAILTABLE#
		WHERE
			#GetFormDtl.DTL_FIELD1# = '#evaluate("GetEntry." & GetFormDtl.LNK_FIELD1)#'
			<CFLOOP INDEX="nFld" FROM="2" TO="5">
				<CFIF evaluate("GetFormDtl.DTL_FIELD" & nFld) NEQ "" AND evaluate("GetFormDtl.LNK_FIELD" & nFld) NEQ "">
					AND #evaluate("GetFormDtl.DTL_FIELD" & nFld)# = '#evaluate("GetEntry." & (evaluate("GetFormDtl.LNK_FIELD" & nFld)))#'
				</CFIF>
			</CFLOOP>
	</CFQUERY>
</CFLOOP>
<CFSET sFormDesc=GetForm.DESCRIPTION>
<CFSET sFormAction="#eform.sender#">
